";
$this->showDataSources ($this->f);
$this->showDateTimeElements ($this->f);
if ($this->CDRTool['filter']['aNumber']) {
$ff[]="a_number";
}
if ($this->CDRTool['filter']['domain']) {
$ff[]="comp_id";
}
if (count($ff)) {
$this->f->freeze($ff);
}
print "
Gateway
";
$this->f->show_element("RemoteAddress","");
print " Local gateway:";
$this->f->show_element("NASIPAddress","");
print " Port Id ";
$this->f->show_element("NASPortId","");
print "
";
print "
Call Id
";
$this->f->show_element("call_id","");
print "
";
print "
Caller Party
";
$this->f->show_element("a_number_comp","");
$this->f->show_element("a_number","");
print " Direction ";
$this->f->show_element("H323CallOrigin","");
print "
";
$this->f->show_element("order_by","");
$this->f->show_element("order_type","");
if ($perm->have_perm("statistics")) {
print " Group by ";
$this->f->show_element("group_by","");
}
print " Max results per page ";
$this->f->show_element("maxrowsperpage","");
print "
";
}
function showSubscriber() {
$this->show();
}
function show() {
global $perm;
foreach ($this->FormElements as $_el) {
${$_el} = $_REQUEST[$_el];
}
if (!$this->export) {
if (!$begin_datetime) {
$begin_datetime="$begin_year-$begin_month-$begin_day $begin_hour:$begin_min";
$begin_datetime_timestamp=mktime($begin_hour, $begin_min, 0, $begin_month,$begin_day,$begin_year);
} else {
$begin_datetime_timestamp=$begin_datetime;
$begin_datetime=Date("Y-m-d H:i",$begin_datetime);
}
$begin_datetime_url=urlencode($begin_datetime_timestamp);
if (!$end_datetime) {
$end_datetime_timestamp=mktime($end_hour, $end_min, 0, $end_month,$end_day,$end_year);
$end_datetime="$end_year-$end_month-$end_day $end_hour:$end_min";
} else {
$end_datetime_timestamp=$end_datetime;
$end_datetime=Date("Y-m-d H:i",$end_datetime);
}
$end_datetime_url=urlencode($end_datetime_timestamp);
} else {
$begin_datetime=Date("Y-m-d H:i",$begin_datetime);
$end_datetime=Date("Y-m-d H:i",$end_datetime);
}
if (!$order_by) {
$order_by=$this->timestampField;
$order_type="DESC";
}
// build an url to be able to log and refine the query
if (!$cdr_table) $cdr_table=$this->table;
$this->url="?cdr_source=$this->cdr_source&cdr_table=$cdr_table";
$this->url=$this->url."&order_by=$order_by&order_type=$order_type";
$this->url=$this->url."&begin_datetime=$begin_datetime_url";
$this->url=$this->url."&end_datetime=$end_datetime_url";
$where = " ($this->startTimeField >= '$begin_datetime' and $this->startTimeField < '$end_datetime')";
if ($this->CDRTool[filter][aNumber]) {
// force user to see only this a_number
$a_number=$this->CDRTool[filter][aNumber];
}
$a_number=trim($a_number);
if ($a_number_comp == "empty") {
$where .= " and $this->aNumberField = ''";
} else {
if ($a_number) {
if (!$a_number_comp) {
$a_number_comp="equal";
}
$a_number_encoded=urlencode($a_number);
$this->url="$this->url"."&a_number=$a_number_encoded";
if ($a_number_comp=="begin") {
$where .= " and ($this->aNumberField like '".addslashes($a_number)."%'";
$s=1;
} elseif ($a_number_comp=="contain") {
$where .= " and ($this->aNumberField like '%".addslashes($a_number)."%'";
$s=1;
} elseif ($a_number_comp=="equal") {
$where .= " and ($this->aNumberField = '".addslashes($a_number)."'";
$s=1;
}
if ($this->CDRTool[filter][aNumber]) {
$where .= " or $this->cNumberField like '".addslashes($a_number)."%') ";
} else {
if ($s) {
$where .= ")";
}
}
$this->url=$this->url."&a_number_comp=$a_number_comp";
}
}
if ($UserName_comp != "empty") {
if ($UserName) {
if (!$UserName_comp) {
$UserName_comp="begin";
}
$UserName_encoded=trim($UserName);
$UserName_encoded=urlencode($UserName);
$this->url="$this->url"."&UserName=$UserName_encoded";
if ($UserName_comp=="begin") {
$where .= " and $this->usernameField like '".addslashes($UserName)."%'";
} elseif ($UserName_comp=="contain") {
$where .= " and $this->usernameField like '%".addslashes($UserName)."%'";
} elseif ($UserName_comp=="equal") {
$where .= " and $this->usernameField = '".addslashes($UserName)."'";
}
}
} else {
$where .= " and $this->usernameField = ''";
}
if ($NASPortId) {
$NASPortId_encoded=urlencode($NASPortId);
$where = "$where"." and $this->NASPortIdField = '".addslashes($NASPortId)."'";
$this->url="$this->url"."&$this->NASPortIdField=$NASPortId_encoded";
}
$call_id_encoded=trim($call_id);
if ($call_id) {
$where = "$where"." and $this->callIdField = '".addslashes($call_id)."'";
$call_id_encoded=urlencode($call_id);
$this->url="$this->url"."&call_id=$call_id_encoded";
}
if ($release_cause) {
$release_cause_hex=dechex($release_cause);
$where = "$where"." and $this->disconnectField = '".addslashes($release_cause_hex)."'";
$this->url="$this->url"."&release_cause=$release_cause";
}
if ($DestinationId) {
$where = "$where"." and $this->DestinationIdField = '".addslashes($DestinationId)."'";
$this->url="$this->url"."&$this->DestinationIdField=$DestinationId";
}
if ($H323CallType) {
$where = "$where"." and $this->H323CallTypeField = '".addslashes($H323CallType)."'";
$this->url="$this->url"."&$this->H323CallTypeField=$H323CallType";
} else {
if ($group_by) {
if ($group_by=="RemoteAddress") {
$where = "$where"." and $this->H323CallTypeField = 'VoIP'";
$this->url="$this->url"."&$this->H323CallTypeField=VoIP";
} else {
$where = "$where"." and $this->H323CallTypeField = 'Telephony'";
$this->url="$this->url"."&$this->H323CallTypeField=Telephony";
}
} else {
$where = "$where"." and ($this->H323CallTypeField = 'VoIP' or
$this->H323CallTypeField = 'Telephony')";
}
}
if ($NASIPAddress) {
$NASIPAddress_encoded=urlencode($NASIPAddress);
$where = "$where"." and $this->localGatewayField = '".addslashes($NASIPAddress)."'";
$this->url="$this->url"."&$this->localGatewayField=$NASIPAddress_encoded";
}
if ($RemoteAddress) {
$where = "$where"." and $this->RemoteAddressField = '".addslashes($RemoteAddress)."'";
$this->url="$this->url"."&RemoteAddress=$RemoteAddress";
}
if ($H323CallOrigin) {
$where = "$where"." and $this->H323CallOriginField = '".addslashes($H323CallOrigin)."'";
$this->url="$this->url"."&$this->H323CallOriginField=$H323CallOrigin";
}
$c_number=trim($c_number);
if (strlen($c_number)) {
# Trim content of dest_form - allow only digits
if ($c_number_comp=="begin") {
$where = "$where"." and $this->cNumberField like '".addslashes($c_number)."%'";
} elseif ($c_number_comp=="equal") {
$where = "$where"." and $this->cNumberField = '".addslashes($c_number)."'";
} elseif ($c_number_comp=="contain") {
$where .= " and $this->cNumberField like '%".addslashes($c_number)."%'";
} else {
$where = "$where"." and $this->cNumberField like '%".addslashes($c_number)."%'";
}
$c_number_encoded=urlencode($c_number);
$this->url=$this->url."&c_number=$c_number_encoded&c_number_comp=$c_number_comp";
}
if ($duration) {
if (preg_match("/\d+/",$duration) ) {
$where .= " and ($this->durationField > 0 and $this->durationField $duration) ";
} elseif ($duration == "zero") {
$where = "$where"." and $this->durationField = 0";
} elseif ($duration == "nonzero") {
$where = "$where"." and $this->durationField > 0";
}
$duration_enc=urlencode($duration);
$this->url="$this->url"."&duration=$duration_enc";
}
$this->url="$this->url"."&maxrowsperpage=$this->maxrowsperpage";
$url_calls = $this->scriptFile.$this->url."&action=search";
if ($group_by) {
$this->url="$this->url"."&group_by=$group_by";
}
$this->url_edit = $this->scriptFile.$this->url."&action=edit";
$this->url_run = $this->scriptFile.$this->url."&action=search";
$this->url_export = $_SERVER["PHP_SELF"].$this->url."&action=search&export=1";
if ($group_by) {
if (!$perm->have_perm("statistics")) {
print "
You do not have the right for statistics.";
return 0 ;
}
$this->group_by=$group_by;
$query= "
select sum($this->durationField) as duration,
count($group_by) as calls, $group_by
from $this->table
where $where
group by $group_by
";
} else {
$query = "select count(*) as records from $this->table where"."$where";
}
dprint("$query");
if ($this->CDRdb->query($query)) {
$this->CDRdb->next_record();
if ($group_by) {
$rows=$this->CDRdb->num_rows();
} else {
$rows = $this->CDRdb->f('records');
}
} else {
print "$this->CDRdb->Error";
$rows = 0;
}
$this->rows=$rows;
if ($this->CDRTool[filter][aNumber]) {
$this->showResultsMenuSubscriber('0',$begin_datetime,$end_datetime);
} else {
$this->showResultsMenu('0',$begin_datetime,$end_datetime);
}
if (!$this->next) {
$i=0;
$this->next=0;
} else {
$i=$this->next;
}
$j=0;
$z=0;
if ($rows>0) {
if ($UnNormalizedCalls=$this->getUnNormalized($where,$cdr_table)) {
dprint("Normalize calls");
$this->NormalizeCDRS($where,$cdr_table);
if (!$this->export && $this->status['normalized'] ) {
printf ("
Found %d CDRs for normalization. ",$this->status['normalized']);
}
}
$this->$rows=$rows;
if ($rows > $this->maxrowsperpage) {
$maxrows=$this->maxrowsperpage+$this->next;
if ($maxrows > $rows) {
$maxrows=$rows;
$prev_rows=$maxrows;
}
} else {
$maxrows=$rows;
}
if ($group_by) {
if ($order_by == $this->inputTrafficField ||
$order_by == $this->outputTrafficField ||
$order_by == $this->durationField ||
$order_by == $this->priceField ||
$order_by == "zeroP" ||
$order_by == "nonzeroP"
) {
$order_by1=$order_by;
} else {
$order_by1="calls";
}
$query= "
select sum($this->durationField) as $this->durationField,
SEC_TO_TIME(sum($this->durationField)) as hours,
count($group_by) as calls, ";
if ($this->priceField) {
$query.=" sum($this->priceField) as price, ";
}
$query.="
$this->H323CallTypeField,
sum($this->inputTrafficField) as $this->inputTrafficField,
sum($this->outputTrafficField) as $this->outputTrafficField,
SUM($this->durationField = '0') as zero,
SUM($this->durationField > '0') as nonzero,
";
if ($order_by=="zeroP" || $order_by=="nonzeroP") {
$query.="
SUM($this->durationField = '0')/count($group_by)*100 as zeroP,
SUM($this->durationField > '0')/count($group_by)*100 as nonzeroP,
";
}
$query.="
$group_by as group_by
from $this->table
where $where
group by $group_by
order by $order_by1 $order_type
limit $i,$this->maxrowsperpage
";
dprint($query);
$this->CDRdb->query($query);
$this->showTableHeaderStatistics();
while ($i<$maxrows) {
$found=$i+1;
$this->CDRdb->next_record();
$seconds =$this->CDRdb->f($this->durationField);
$seconds_print =number_format($this->CDRdb->f($this->durationField),0);
$minutes =number_format($this->CDRdb->f($this->durationField)/60,0,"","");
$minutes_print =number_format($this->CDRdb->f($this->durationField)/60,0);
$hours =$this->CDRdb->f('hours');
$calls =$this->CDRdb->f('calls');
if ($this->priceField) {
$price =$this->CDRdb->f('price');
}
$AcctInputOctets =number_format($this->CDRdb->f($this->inputTrafficField)/1024,2,".",".");
$AcctOutputOctets =number_format($this->CDRdb->f($this->outputTrafficField)/1024,2,".",".");
$H323CallType =$this->CDRdb->f($this->H323CallTypeField);
$AcctTerminateCause =$this->CDRdb->f($this->disconnectField);
$mygroup =$this->CDRdb->f('group_by');
$zero =$this->CDRdb->f('zero');
$nonzero =$this->CDRdb->f('nonzero');
$success =number_format($nonzero/$calls*100,2,".",".");
$failure =number_format($zero/$calls*100,2,".",".");
if ($group_by==$this->disconnectField) {
if ($mygroup=="AC") {
$mygroup="22";
}
$DisconnectCause=hexdec($mygroup);
$mygroup_print=hexdec($mygroup);
$mygroup_enc=urlencode($DisconnectCause);
} else {
$DisconnectCause ="";
$mygroup_print=$mygroup;
$mygroup_enc=urlencode($mygroup);
}
$rr=floor($found/2);
$mod=$found-$rr*2;
if ($mod ==0) {
$inout_color="lightgrey";
} else {
$inout_color="white";
}
if ($group_by == $this->disconnectField) {
$description=$this->disconnectCodesDescription[$DisconnectCause];
} else if ($group_by==$this->DestinationIdField) {
if ($this->CDRTool['filter']['aNumber']) {
$description=$this->destinations[$this->CDRTool['filter']['aNumber']][$mygroup];
} else if ($this->CDRTool['filter']['domain']) {
$description=$this->destinations[$this->CDRTool['filter']['domain']][$mygroup];
} else {
$description=$this->destinations["default"][$mygroup];
}
} else {
$description="";
}
if ($group_by==$this->aNumberField) {
$traceField="a_number";
} else if ($group_by==$this->cNumberField) {
$traceField="c_number";
} else if ($group_by==$this->disconnectField) {
$traceField="release_cause";
} else {
$traceField=$group_by;
}
if (!$this->export) {
$pricePrint=number_format($price,4);
print "